package 分类.前缀和;

public class 区域和检索数组不可变 {
    class NumArray {
        //前缀和数组
        int[] preSum;
        public NumArray(int[] nums) {
            preSum[0]=nums[0];
            for(int i=1;i<nums.length;i++){
                preSum[i]=preSum[i-1]+nums[i];
            }
        }
        public int sumRange(int left, int right) {
            return preSum[right]=preSum[left-1];
        }
    }
}
